//
//  WYTableViewCell.swift
//  weibo
//
//  Created by 王玉东 on 16/4/12.
//  Copyright © 2016年 wyd. All rights reserved.
//

import UIKit
//import SnapKit
import SnapKit


class WYTableViewCell: UITableViewCell {
    
private lazy var originalView:WYStatusView = WYStatusView()
private lazy var statusBar:WYToolsBar = WYToolsBar()
private lazy var retweetedView: WYStatusRetweetedView = WYStatusRetweetedView()
var toolBarTopCons: Constraint?

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: .Default, reuseIdentifier: reuseIdentifier)
        
        setUI()
    
        selectionStyle = .None
    }
    

    var statusModel:WYStatusModel? {
        didSet{
            
           originalView.statusModel = statusModel
           statusBar.statusModel = statusModel
            self.toolBarTopCons?.uninstall()
            if statusModel?.status?.retweeted_status != nil {
            
             statusBar.snp_updateConstraints(closure: { (make) -> Void in
             self.toolBarTopCons =  make.top.equalTo(retweetedView.snp_bottom).constraint
             })
                retweetedView.hidden = false
                retweetedView.statusModel = statusModel
            }else{
            
                statusBar.snp_updateConstraints(closure: { (make) -> Void in
                self.toolBarTopCons  =  make.top.equalTo(originalView.snp_bottom).constraint
                })
            retweetedView.hidden = true
                
            retweetedView.statusModel = nil
            }
            
            
        }
        
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setUI(){
    
   // backgroundColor = randomColor()
        
    contentView.addSubview(originalView)
    contentView.addSubview(retweetedView)
    contentView.addSubview(statusBar)
        
    originalView.snp_makeConstraints { (make) -> Void in
        make.left.top.right.equalTo(contentView)
        //make.height.equalTo(100)
        }
   retweetedView.snp_makeConstraints { (make) -> Void in
    make.top.equalTo(originalView.snp_bottom)
    make.left.right.equalTo(contentView)
    //make.height.equalTo(36)
        }
        
statusBar.snp_makeConstraints { (make) -> Void in
    self.toolBarTopCons = make.top.equalTo(retweetedView.snp_bottom).constraint
        make.left.right.equalTo(contentView)
        make.height.equalTo(36)
        
        }
originalView.backgroundColor = UIColor.whiteColor()
        contentView.snp_makeConstraints { (make) -> Void in
            make.left.right.top.equalTo(self)
            make.bottom.equalTo(statusBar.snp_bottom)
        }
    }


    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
